import { $ } from './library/jquery-module.js';
import './library/jquery-extend-slider.js';
// import 'https://cdn.bootcdn.net/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js';


$('#slider').slider();

$.ajax({
    type: "get",
    url: "../../interface/index.php",
    dataType: "json",
    success: function(res) {
        let temp = '';
        res.forEach(function(elm, _index) {
            let pics = JSON.parse(elm.picture);
            let goodstitle = JSON.parse(elm.title);

            temp += `<a href="./goods.html?id=${elm.id}">
                        <img src="../${pics[0].src}" alt="">
                        <span></span>
                        <p>${goodstitle[0].name.slice(0,20)+'...'}</p>
                        <div>${elm.price}</div>
                    </a>`;

            // jQuery(document).ready(function($) {
            //     $('img.lazy').lazyload({
            //         placeholder: '../img/lazy-img.png',
            //         effect: 'fadeIn'
            //     });
            // });
        });

        $('.internationgoods>.othergoods').html(temp);
    }
});

// 导航

$('#nav-list>li>a').on('click', function() {
    let elm = $(`#${$(this).attr('title')}`);
    let elmtop = elm.offset().top - 50;

    $('html').animate({
        scrollTop: elmtop
    }, 1000, function() {
        console.log('end')
    });
});
$(window).on('scroll', function() {
    let dctop = $(document).scrollTop();
    // console.log(dctop);

    if (dctop < 660) {
        $('#nav-list').css({
            'width': '0',
            'height': '0',
            'opacity': '0'
        });

        $('#index-search').slideUp(500);

        $('#index-search>input').css('display', 'none');
        $('#index-search>button').css('display', 'none');

    } else if (dctop >= 660) {
        $('#nav-list').css({
            'width': '36px',
            'height': '200px',
            'opacity': '1'
        });

        $('#index-search').slideDown(500);
        $('#index-search>input').css('display', 'block');
        $('#index-search>button').css('display', 'block');
    }

    if (dctop > 1063 && dctop < 1685) {
        $('#nav-list>li>a').removeClass('active').eq(1).addClass('active');

    } else if (dctop > 1685 && dctop < 2400) {
        $('#nav-list>li>a').removeClass('active').eq(2).addClass('active');
    } else if (dctop > 2400) {
        $('#nav-list>li>a').removeClass('active').eq(3).addClass('active');

    }
});